package tp.pr5.instructions;

import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;
import tp.pr5.instructions.exceptions.InstructionExecutionException;
import tp.pr5.instructions.exceptions.WrongInstructionFormatException;
import tp.pr5.items.ItemContainer;

/**
 * Shows the game help with all the instructions that the robot can execute. This instruction works if the user writes HELP or AYUDA
 */
public class HelpInstruction implements Instruction
{

	private RobotEngine engine;

	/**
	 * Default Constructor
	 */
	public HelpInstruction()
	{

	}

	/**
	 * Parses the String returning an instance of HelpInstruction or throwing a WrongInstructionFormatException()
	 * 
	 * @param cad string given
	 */
	@Override
	public Instruction parse(String cad) throws WrongInstructionFormatException
	{
		cad = cad.toUpperCase();
		if(cad.equals("HELP") || cad.equals("AYUDA"))
		{
			return new HelpInstruction();
		}
		throw new WrongInstructionFormatException();
	}

	/**
	 * Fixes the current context, i.e., the robot engine and the navigation module
	 * 
	 * @param engine RobotEngine
	 * @param navigation NavigationModule
	 * @param robotContainer ItemContainer
	 * 
	 */
	@Override
	public void configureContext(RobotEngine engine, NavigationModule navigation, ItemContainer robotContainer) 
	{
		this.engine = engine;
	}

	/**
	 * Prints the help string of every instruction. It delegates to the Interpreter class.
	 */
	@Override
	public void execute() throws InstructionExecutionException
	{
		try
		{
			this.engine.requestHelp();
			
		} catch(Exception e){
			throw new InstructionExecutionException();
		}
	}

	/**
	 * Help syntax
	 */
	@Override
	public String getHelp()
	{
		return "HELP|AYUDA";
	}
	
}
